<?php

/**
 * This is the model class for table "sys_network".
 *
 * The followings are the available columns in table 'sys_network':
 * @property string $network_id
 * @property string $network_mid
 * @property string $network_position
 * @property string $network_sponsor_network_id
 * @property string $network_upline_network_id
 * @property string $network_downline_left_network_id
 * @property string $network_downline_right_network_id
 * @property string $network_total_node_left
 * @property string $network_total_node_right
 *
 * The followings are the available model relations:
 * @property SysBonusTransfer[] $sysBonusTransfers
 * @property SysMember $sysMember
 * @property SysMemberLog[] $sysMemberLogs
 * @property SysMemberTestimony[] $sysMemberTestimonys
 * @property SysNetgrowMaster[] $sysNetgrowMasters
 * @property SysPassword $sysPassword
 * @property SysRewardLog[] $sysRewardLogs
 * @property SysSerial[] $sysSerials
 * @property SysSerial[] $sysSerials1
 * @property SysStockist $sysStockist
 */
class sys_network extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return sys_network the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'sys_network';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('network_mid, network_position', 'required'),
            array('network_mid', 'length', 'max' => 15),
            array('network_position', 'length', 'max' => 1),
            array('network_sponsor_network_id, network_upline_network_id, network_downline_left_network_id, network_downline_right_network_id, network_total_node_left, network_total_node_right', 'length', 'max' => 10),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('network_level_status, network_id, network_mid, network_position, network_sponsor_network_id, network_upline_network_id, network_downline_left_network_id, network_downline_right_network_id, network_total_node_left, network_total_node_right', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'rel_network_to_bonus_transfer' => array(self::HAS_MANY, 'sys_bonus_transfer', 'bonus_transfer_network_id'),
            'rel_network_to_member' => array(self::HAS_ONE, 'sys_member', 'member_network_id'),
            'rel_network_to_member_log' => array(self::HAS_MANY, 'sys_member_log', 'member_log_network_id'),
            'rel_network_to_member_testimony' => array(self::HAS_MANY, 'sys_member_testimony', 'member_testimony_network_id'),
            'rel_network_to_netgrow_master' => array(self::HAS_MANY, 'sys_netgrow_master', 'netgrow_master_network_id'),
            'rel_network_to_password' => array(self::HAS_ONE, 'sys_password', 'password_network_id'),
            'rel_network_to_reward_log' => array(self::HAS_MANY, 'sys_reward_log', 'reward_log_network_id'),
            'rel_network_to_serial1' => array(self::HAS_MANY, 'sys_serial', 'serial_user_network_id'),
            'rel_network_to_serial2' => array(self::HAS_MANY, 'sys_serial', 'serial_buyer_network_id'),
            'rel_network_to_stockist' => array(self::HAS_ONE, 'sys_stockist', 'stockist_network_id'),
            'rel_network_to_buyer'=>array(self::HAS_MANY,'sys_serial_buyer','serial_buyer_network_id'),
            'rel_network_to_serial_product_buyer'=>array(self::HAS_MANY,'sys_serial_product_buyer','serial_products_buyer_network_id'),
	    'rel_network_to_ewallet_withdrawal'=>array(self::HAS_MANY,'sys_ewallet_withdrawal','ewallet_withdrawal_network_id'),
            );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'network_id' => 'Network',
            'network_mid' => 'Member ID',
            'network_position' => 'Position',
            'network_sponsor_network_id' => 'Sponsor ID',
            'network_upline_network_id' => 'Upline ID',
            'network_downline_left_network_id' => 'Downline Left ID',
            'network_downline_right_network_id' => 'Downline Right ID',
            'network_total_node_left' => 'Total Node Left',
            'network_total_node_right' => 'Total Node Right',
            'network_level_status' => 'Level',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('network_id', $this->network_id, true);
        $criteria->compare('network_mid', $this->network_mid, true);
        $criteria->compare('network_position', $this->network_position, true);
        $criteria->compare('network_sponsor_network_id', $this->network_sponsor_network_id, true);
        $criteria->compare('network_upline_network_id', $this->network_upline_network_id, true);
        $criteria->compare('network_downline_left_network_id', $this->network_downline_left_network_id, true);
        $criteria->compare('network_downline_right_network_id', $this->network_downline_right_network_id, true);
        $criteria->compare('network_total_node_left', $this->network_total_node_left, true);
        $criteria->compare('network_total_node_right', $this->network_total_node_right, true);
        $criteria->compare('network_level_status', $this->network_level_status, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}
